<!--
 * @Desc: 报修详情页面
 * @version: v1.00
 * @Author: harry
 * @Date: 2023-8-10 21:45:31
 * @LastEditors: harry
 * @LastEditTime: 2024-04-07 20:57:16
-->
<template>
  <div class="detail">
    <div class="detail-info">
      <div class="detail-info-status">
        <span>{{ rec.info.equipmentRepair?.repairType }}</span>
        <span v-if="rec.info.equipmentRepair?.status === 1">已维修</span>
        <span class="orange" v-else>待维修</span>
      </div>

      <div class="detail-info-address">
        <svg-icon icon-class="addr" />
        <span class="ellipsisStyle"
          >{{ rec.info.equipmentRepair?.buildingLocationName
          }}{{ rec.info.equipmentRepair?.roomLocationName ? "/" : null
          }}{{ rec.info.equipmentRepair?.roomLocationName }}</span
        >
      </div>

      <!-- dayjs(rec.info.equipmentRepair?.createTime).format("YYYY-MM-DD hh:mm") -->
      <div class="detail-info-time">
        <svg-icon icon-class="time" />
        <span>{{ rec.info.equipmentRepair?.createTime }}</span>
      </div>

      <div
        class="detail-info-content"
        v-html="rec.info.equipmentRepair?.repairDesc.replace(/\n/g, '<br/>')"
      ></div>

      <PreviewComp :fileList="rec.info?.equipmentRepairFiles" />
    </div>
    <!-- 报修人查看维修详情 -->
    <div v-if="rec.type === 'home'">
      <FixDetail
        :list="rec.info.equipmentRepairResult"
        :NoRepairInfo="rec.info.equipmentRepair"
      />
    </div>

    <!-- 查看报修人填报信息 -->
    <div v-else>
      <RepairDetail
        :list="rec.info.equipmentRepairResult"
        :info="rec.info.equipmentRepair"
      />
    </div>

    <van-popup v-model:show="rec.show">
      <div>
        <div class="title">提示</div>
        <div class="message">该维修单已经指派维修人员</div>
        <Btn
          btnTitle="确定"
          @submit="router.push('/home')"
          @cancel="router.push('/home')"
        />
      </div>
    </van-popup>

    <van-popup v-model:show="rec.noRshow">
      <div>
        <div class="title">提示</div>
        <div class="message">该维修单还未指派维修人员</div>
        <Btn
          btnTitle="确定"
          @submit="router.push('/home')"
          @cancel="router.push('/home')"
        />
      </div>
    </van-popup>
  </div>
</template>

<script lang="ts" setup>
import { reactive } from "vue";
import { getRepairDetail } from "@/service/modules/repair";
import { useRoute } from "vue-router";
import router from "@/router";
import Btn from "@/views/repairList/set/cnps/btn/index.vue";
import FixDetail from "./cpns/FixDetail.vue";
import RepairDetail from "./cpns/RepairDetail.vue";
import PreviewComp from "@/components/previewComp/index.vue";
import LocalCache from "@/utils/cache";
document.title = "报修详情";
const route = useRoute();
const rec = reactive({
  info: {},
  repairDesc: "",
  type: route.query.type,
  fileList: [],
  show: false,
  noRshow: false,
});

// 获取详情
getDetailFn();
async function getDetailFn() {
  const id = route.query.id;
  const { data } = await getRepairDetail(id);
  rec.info = data;
  // 待维修
  if (rec.info.equipmentRepair?.status !== 1) {
    if (rec.type !== "home") {
      // 维修员身份
      if (
        data?.equipmentRepair?.persons.length > 1 &&
        !data?.equipmentRepair?.repairPerson
      ) {
        // 多个维修员 && 未指派维修员
        rec.noRshow = true;
        return false;
      } else {
        // 单个维修员
        const { personId } = LocalCache.getSession("userInfo");
        if (data?.equipmentRepair?.repairPerson !== personId) {
          rec.show = true;
          return false;
        }
      }
    }
  }
  // 已维修
  if (rec.info.equipmentRepair?.status === 1) {
    if (rec.type !== "home") {
      // 维修员身份
      // 单个维修员
      const { personId } = LocalCache.getSession("userInfo");
      if (data?.equipmentRepair?.repairPerson !== personId) {
        rec.show = true;
        return false;
      }
    }
  }
}
</script>

<style lang="less" scoped>
.detail {
  background: #fff;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  &-info {
    padding: 8px 16px;
    background: #fff;
    &-status {
      display: flex;
      justify-content: space-between;
      align-items: center;
      > span:first-child {
        font-size: 18px;
        line-height: 40px;
        font-weight: bold;
        color: #303233;
      }
      > span:nth-child(2),
      .orange {
        width: 56px;
        height: 24px;
        background: #dcdcdc;
        border-radius: 4px;
        font-size: 12px;
        line-height: 24px;
        color: #fff;
        text-align: center;
      }
      .orange {
        background: #fe922a !important;
      }
    }
    &-address,
    &-time {
      display: flex;
      align-items: center;
      margin-top: 8px;
      svg {
        margin-right: 11px;
      }
      > span {
        font-size: 14px;
        line-height: 22px;
        color: #303233;
      }
    }
    &-address {
      svg {
        margin-right: 13px;
      }
    }
    &-content {
      margin-top: 12px;
      font-size: 14px;
      line-height: 32px;
      color: #303233;
      word-wrap: break-word;
    }
    &-imgs {
      margin-top: 8px;
      display: flex;
      // justify-content: space-evenly;
      > div {
        width: 108px;
        height: 108px;
        border-radius: 4px;
        margin-right: 4px;
        margin-bottom: 8px;
        img {
          width: 100%;
          height: 100%;
        }
      }
    }
  }
  /deep/ .van-popup {
    width: 295px;
    border-radius: 10px;
    padding: 16px;
    .title {
      font-size: 16px;
      line-height: 22px;
      letter-spacing: 1px;
      font-weight: 500;
      text-align: center;
    }
    .message {
      margin-top: 20px;
      margin-bottom: 18px;
      padding: 0 8px;
      font-size: 14px;
      line-height: 22px;
      color: #919599;
      letter-spacing: 1px;
    }
    .btn {
      button {
        width: 124px;
        border-width: 0.5px;
      }
    }
  }
}
</style>
